package com.taofuxn.yycreazy.mvp.presenter;

import com.taofuxn.yycreazy.MyApp;
import com.taofuxn.yycreazy.database.dao.DaoSession;
import com.taofuxn.yycreazy.database.model.Collection;
import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.mvp.view.ICollectView;

import java.util.ArrayList;

/**
 * 收藏夹的presenter
 * Created by taofuxn on 2016/9/20.
 */
public class CollectionPresenter extends BasePresenter{
    private ICollectView mICollectView;

    private DaoSession mDaoSession;

    public CollectionPresenter(ICollectView mICollectView){
        this.mICollectView = mICollectView;
        mDaoSession = MyApp.getInstance().getmDaoUtil().getDaoSession();
        onAttachView(mICollectView);
    }

    /**
     * 从数据库中获取收藏列表
     * @return
     */
    public ArrayList<Collection> getCollectionDate(){
        return (ArrayList<Collection>) mDaoSession.getCollectionDao().queryBuilder().list();
    }

    public void deleteCollectionByEntity(Collection m){
        mDaoSession.getCollectionDao().delete(m);
    }
}
